package leetcode.数组;

public class 存在重复元素二219 {
    public static boolean containsNearbyDuplicate(int[] nums, int k) {
        java.util.HashMap<Integer,Integer> hashMap = new java.util.HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            if(hashMap.containsKey(nums[i])){
                if(java.lang.Math.abs(i - hashMap.get(nums[i])) <= k)
                    return true;
                hashMap.put(nums[i],i);
                continue;
            }
            hashMap.put(nums[i],i);
        }
        return false;

    }

    public static void main(String[] args) {
        int[] nums = {1,0,1,1};
        containsNearbyDuplicate(nums,1);
    }
}
